<template>
  <div class="worklife">
    <div class="tip">工作经历</div>
    <div class="bottom" v-for="(item, index) in staffWorkExpList" :key="index">
      <div style="margin-right:5px;">{{ `${index + 1}.` }}</div>
      <el-input
        placeholder=" 请输入工作经历"
        maxlength="100"
        show-word-limit
        v-model="staffWorkExpList[index].experience"
      >
      </el-input>
      <el-button
        style="background-color:#fd804c;color: #fff;"
        @click="add"
        v-if="index === 0"
        >新增经历</el-button
      >
      <el-button
        style="background-color:#fd804c;color: #fff;"
        @click="goDelete(index)"
        v-if="index !== 0"
        >删除经历</el-button
      >
    </div>
  </div>
</template>

<script>
export default {
  props: {
    staffWorkExpList1: {
      required: false
    }
  },
  data() {
    return {
      staffWorkExpList: [
        {
          experience: ""
        }
      ]
    };
  },
  methods: {
    add() {
      this.staffWorkExpList.push({
        experience: ""
      });
    },
    goDelete(index) {
      this.staffWorkExpList.splice(index, 1);
    },
    sendMsg() {
      this.$emit("save", this.staffWorkExpList);
    },
    initData() {
      if (this.$route.query.staffCode) {
        const withoutIdList = this.staffWorkExpList1.map(item => {
          return {
            experience: item.experience
          };
        });
        this.staffWorkExpList = withoutIdList;
      }
    }
  },
  watch: {
    staffWorkExpList: {
      handler() {
        this.sendMsg();
      },
      deep: true
    },
    staffWorkExpList1(newvalue) {
      if (newvalue) {
        this.initData();
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.worklife {
  background-color: #fff;
  border-top: 10px solid #ebeef1;
  .tip {
    font-size: 18px;
    font-weight: 900;
    padding-left: 20px;
    height: 60px;
    line-height: 60px;
  }
  /deep/ .bottom {
    margin: 0 20px;
    padding-bottom: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    .el-input__inner {
      height: 30px;
    }
    .el-button {
      height: 30px;
      margin-left: 20px;
      line-height: 30px;
      padding: 0px 5px;
    }
  }
}
</style>
